/*
 * Copyright (c) 2007, TopCoder, Inc. All rights reserved.
 */

using System;

namespace TopCoder.Util.Calendar.Entry
{
    /// <summary>
    /// <para>This class defines the types for calendar entries.</para>
    /// <para>
    /// A calendar entry type has a unique identifier and a textual description. The calendar entry types
    /// will be maintained by the using application.
    /// </para>
    /// </summary>
    /// <remarks>
    /// Thread Safety: This class is not thread safe since it's highly mutable.
    /// </remarks>
    ///
    /// <author>snower, fuyun</author>
    /// <version>1.0</version>
    /// <copyright>Copyright (c) 2007, TopCoder, Inc. All rights reserved.</copyright>
    public class CalendarEntryType
    {
        /// <summary>
        /// <para>Represents the id of this type.</para>
        /// <para>
        /// It's initialized in the constructor and can be accessed/modified via the namesake property.
        /// This is a must-set field, using application must make sure to set it. This field can be set to
        /// any non-negative integer.
        /// </para>
        /// </summary>
        private int typeId;

        /// <summary>
        /// <para>Represents the description of this type.</para>
        /// <para>
        /// It's initialized in the constructor and can be accessed/modified via the namesake property.
        /// This is a must-set field, using application must make sure to set it. It could be set to any
        /// meaningful string but should not be null or empty once set.
        /// </para>
        /// </summary>
        private string description;

        /// <summary>
        /// Represents the property for the id of this calendar entry type.
        /// </summary>
        /// <value>The id of this calendar entry type.</value>
        /// <exception cref="ArgumentException">
        /// If value is negative when setting this property.
        /// </exception>
        public int TypeId
        {
            get
            {
                return typeId;
            }

            set
            {
                if (value < 0)
                {
                    throw new ArgumentException(
                        "The id of the calendar entry type could not be set negative value.", "typdId");
                }
                typeId = value;
            }
        }

        /// <summary>
        /// Represents the property for the description of this calendar entry type.
        /// </summary>
        /// <value>The description of this calendar entry type.</value>
        /// <exception cref="ArgumentNullException">
        /// If value is null when setting this property.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// if value is empty when setting this property.
        /// </exception>
        public string Description
        {
            get
            {
                return description;
            }

            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException(
                        "description", "The description of the calendar entry type could not be set null.");
                }
                if (value.Trim().Length == 0)
                {
                    throw new ArgumentException(
                        "The description of this calendar entry type could not be empty.", "description");
                }
                description = value;
            }
        }

        /// <summary>
        /// Creates a new <c>CalendarEntryType</c> instance with the given id and description.
        /// </summary>
        /// <param name="typeId">the id of this type.</param>
        /// <param name="description">the description of this type.</param>
        /// <exception cref="ArgumentNullException">
        /// If description is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If description is an empty string or the typeId is negative.
        /// </exception>
        public CalendarEntryType(int typeId, string description)
        {
            TypeId = typeId;
            Description = description;
        }

        public override int GetHashCode()
        {
            return typeId;
        }

        public override bool Equals(object obj)
        {
            if ( obj == null || !(obj is CalendarEntryType))
                return false;
            CalendarEntryType o = (CalendarEntryType) obj;
            return o.typeId == typeId && o.description == description;
        }
    }
}